
cc.Class({
    extends: cc.Component,

    properties: {
        Fy_NodeHall:cc.Node,
        Fd_HeadPortrait:cc.Sprite,
        Fd_subject:cc.Label,
        Fd_Expressions:cc.Sprite,
        package:cc.SpriteAtlas, 
        Fd_InputBox:cc.EditBox,
        Fd_Lssue:cc.Node,
        L_EditBox:cc.EditBox,
        Fd_Tips:cc.Node
    }, 
    onLoad:function(){
        var id = parseInt(Math.random()*25,10);
        this.Fd_Expressions.spriteFrame = this.package.getSpriteFrame("skin_"+id);
        this.onChangeSubject();
    },
    info(node){
        this.upperNode = node;
        this.node.active = true;
    },
    onLoadingHead(){
        var urls = UserData.UserInfo.avatarUrl;
        var self = this;
        cc.loader.load({url: urls, type: 'png'}, function (err, texture) {
            self.Fd_HeadPortrait.spriteFrame = new cc.SpriteFrame(texture);
        });
    },
    onChangeSubject(){//parseInt(Math.random()*(max-min+1)+min,10);
        var id = parseInt(Math.random()*7,10);
        var name = ["回家","吃饭了吗？","去玩","逛街","请客","喜事","丧事"];
        this.Fd_subject.string = "题目:"+name[id];
    },
    onReturn(){
        this.node.active = false;
        if(this.upperNode){
            this.upperNode.active = true;
            if(this.upperNode.name == "Fy_NodeHall"){
                window.GameClubButton.show();
            }
        }
        this.upperNode = null;
    },
    onConfirmInput(){ // 设置答案
        if(this.Fd_InputBox.string.length > 1){
          console.log("回答成功");
          var sefl = this;
          wx.cloud.callFunction({
            name: 'releaseWorks',
            data: {
                releaseTime: new Date().getTime(),       // 发布时间
                openName: UserData.UserInfo.nickName,          // 作者名字
                openId: UserData.UserInfo.openId,            // 作者id
                portrait: UserData.UserInfo.avatarUrl,         // 作者头像url
                region: "河南",            // 方言所在地
                dialect: "哦有面",           // 方言
                mandarin: "右面",          // 普通话
            },
            complete(res){
                if(res.result == 1){
                    UserData.UserInfo.works+=1;
                    sefl.onTips("发布成功");
                    sefl.Fd_InputBox.string = "";
                    sefl.onChangeSubject();
                    ddz.onLoadingData.onMyWork();
                }else console.log("发布失败");
            }
         });
        }else{
            this.onTips("请输入答案后在确定");
        }
    },
    onTips(content){
        this.Fd_Tips.getComponent(cc.Label).string = content;
        this.Fd_Tips.active = true;
        this.scheduleOnce(function() {
            this.Fd_Tips.active = false;
        }, 2);  
    },
    onSetAQuestion(){
        this.Fd_Lssue.active = true;
    },
    onCancelSetAQuestion(){
        this.Fd_Lssue.active = false;
    },
    onConfirmSetAQuestion(){
        if(this.L_EditBox.string.length > 1){
            this.Fd_subject.string = "题目:"+this.L_EditBox.string;
            this.Fd_Lssue.active = false;
        }else{
            this.Fd_Tips.active = true;
            this.scheduleOnce(function() {
                this.Fd_Tips.active = false;
            }, 2);
        }
    },
    onScreenshotsSharing(){
        ddz.onScreenshotsSharing();
    }
});
